package thoughtworks.test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;

/*
 * Main class to convert roman to number and number to roman
 */

public class MainClass {
	public static void main(String[] args) {
		
		RomanToNumberConversion romanConversionObj = new RomanToNumberConversion();
		NumberToRomanConversion numberConversionObj = new NumberToRomanConversion();
		TextInputConversion txtInputConvObj = new TextInputConversion(romanConversionObj);
		System.out.println("Enter your choice: ");
		System.out.println("1. Convert Roman to Number.");
		System.out.println("2. Convert Number to Roman.");
		System.out.println("3. Text input.");
		
		try{
		    BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
		    String s = bufferRead.readLine();
		    String input;
		    switch(Integer.valueOf(s)){
		    case 1:
		    	System.out.println("Enter input:");
		    	input=bufferRead.readLine();;
		    	int result = romanConversionObj.convertRomanNumeral(input);
		    	System.out.println(result);
		    	break;
		    case 2:
		    	System.out.println("Enter input:");
		    	input=bufferRead.readLine();;
		    	String res = numberConversionObj.convertNumberToRoman(input);
		    	System.out.println(res);
		    	break;
		    case 3:
		    	txtInputConvObj.convert(new BufferedReader(new FileReader("input.txt")));
		    	break;
		    default :
		    	System.out.println("INVALID INPUT");
		    }
		}
		catch(NumberFormatException ex){
			System.out.println("INVALID INPUT");
		}
		catch(Exception e)
		{
			System.out.println(e.getMessage());
		}
	}
}
